<script type="text/javascript" src="/public/tool/socket.io-1.3.5.js"></script>
<audio id="video" controls="controls" preload hidden>
    <source src="/public/admin/img/recharge.mp3"/>
</audio>
<script type="text/javascript">
    function playMusic(loop=false) {
        var id = '#video';
        var pobj = $(id);
        var player = pobj[0];
        if (player.paused) { /*如果已经暂停*/
            player.play();
        } else {
            // player.pause();
        }
        if(loop){
            pobj.attr('loop','loop'); // 循环播放
        }
    }
</script>
<script type="text/javascript">
    $(function () {
        var socket = io('ws://{{host}}', {
            query: {
                room: 'demo',
            }, transports: ['websocket']
        });
        socket.on('connect', () => {
            const id = socket.id;
            console.log('#connect,', id);
            socket.emit('server', 'ssss');
        });
        socket.on('message', function (data) {
            socket.emit('my other event', {my: 'data'});
        });
        socket.on('play', function (data) {
            console.log('#play,', data);
            playMusic();
            open_order_tips();
        });
        socket.on('res', function (data) {
            console.log('res', data);
        });
        // 系统事件
        socket.on('disconnect', msg => {
            console.log('#disconnect', msg);
        });
        socket.on('disconnecting', () => {
            console.log('#disconnecting');
        });
        socket.on('error', () => {
            console.log('#error');
        });
        window.socket = socket;
    });
</script>